/**
 * 
 */
package com.geekteam.geometrychess.game.entity;


/**
 * @author MtRol
 * 
 */
public abstract class Piece {
	protected int mId;
	protected Color mColor;
	protected Location mCurrentLocation;

	public Piece(int id, Color color, Location location) {
		mId = id;
		mColor = color;
		mCurrentLocation = location;
	}

	/*public boolean canMoveTo(Board board, Location lo) {
		// check xem quan co co trong ban co khong
		if (!inBoard(lo)) {
			return false;
		}

		// check xem tai diem toi do co quan co nao hay khong
		Piece dstPiece = board.getPieceAt(lo);
		if (dstPiece != null) {
			return false;
		}

		// check quan co theo thu tu
		// ngang, doc, cheo
		if (mCurrentLocation.getPosX() == lo.getPosX()) {
			for (int i = Math.min(mCurrentLocation.getPosY() + 1,
					lo.getPosY() + 1); i < Math.max(mCurrentLocation.getPosY(),
					lo.getPosY()); i++) {
				if (board.getPieceAt(mCurrentLocation.getPosX(), i) != null) {
					return false;
				}
			}
			return true;
		} else if (mCurrentLocation.getPosY() == lo.getPosY()) {
			for (int i = Math.min(mCurrentLocation.getPosX() + 1,
					lo.getPosX() + 1); i < Math.max(mCurrentLocation.getPosX(),
					lo.getPosX()); i++) {
				if (board.getPieceAt(i, mCurrentLocation.getPosY()) != null) {
					return false;
				}
			}
			return true;
		} else if (Math.abs((mCurrentLocation.getPosX() - lo.getPosX())) == Math
				.abs((mCurrentLocation.getPosY() - lo.getPosY()))) {
			//neu current x < lo x va current y < lo y hoac la current x > lo x va current y > lo y
			//check duong cheo tu trai qua phai, sau do check duong cheo tu phai qua trai
			if(((mCurrentLocation.getPosX() < lo.getPosX()) && (mCurrentLocation.getPosY() < lo.getPosY()))
					|| ((mCurrentLocation.getPosX() > lo.getPosX()) && (mCurrentLocation.getPosY() > lo.getPosY()))){
				
				int x = Math.min(mCurrentLocation.getPosX(), lo.getPosX());
				int y = Math.min(mCurrentLocation.getPosY(), lo.getPosY());
				x++;y++;
				while((x!=Math.max(mCurrentLocation.getPosX(), lo.getPosX()))&&(y!=Math.max(mCurrentLocation.getPosY(), lo.getPosY()))){
					if(board.getPieceAt(x, y)!=null){
						return false;
					}
					x++;y++;
				}
				
				return true;
			}else if(((mCurrentLocation.getPosX() > lo.getPosX()) && (mCurrentLocation.getPosY() < lo.getPosY()))
					|| ((mCurrentLocation.getPosX() < lo.getPosX()) && (mCurrentLocation.getPosY() > lo.getPosY()))){
				int x = Math.max(mCurrentLocation.getPosX(), lo.getPosX());
				int y = Math.min(mCurrentLocation.getPosY(), lo.getPosY());
				x--;y++;
				while((x!=Math.min(mCurrentLocation.getPosX(), lo.getPosX()))&&(y!=Math.max(mCurrentLocation.getPosY(), lo.getPosY()))){
					if(board.getPieceAt(x, y)!=null){
						return false;
					}
					x--;y++;
				}
				
				return true;
			}
		}

		return false;
	}

	public boolean inBoard(Location lo) {
		return inBoard(lo.getPosX(), lo.getPosY());
	}

	public boolean inBoard(int x, int y) {
		return inBoard(ChessUtils.TO_SQ(x, y));
	}

	public boolean inBoard(int pos) {
		return ChessUtils.IN_BOARD[pos] == 1;
	}*/

	public enum Color {
		white, black
	}
	
	public int getId(){
		return mId;
	}
	
	public Location getLocation(){
		return mCurrentLocation;
	}
	
	public void setLocation(Location location){
		this.mCurrentLocation = location;
	}
	
	public Color getColor(){
		return mColor;
	}
}
